package com.agriculture.competition.controller;

import com.agriculture.common.core.utils.poi.ExcelUtil;
import com.agriculture.common.core.web.controller.BaseController;
import com.agriculture.common.core.web.domain.AjaxResult;
import com.agriculture.common.core.web.page.TableDataInfo;
import com.agriculture.common.log.annotation.Log;
import com.agriculture.common.log.enums.BusinessType;
import com.agriculture.competition.domain.JaCase;
import com.agriculture.competition.service.IJaCaseService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 案件Controller
 *
 * @author agriculture
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/case")
public class JaCaseController extends BaseController {

    @Autowired
    private IJaCaseService jaCaseService;

    /**
     * 查询案件列表
     */
    // @RequiresPermissions("competition:case:list")
    @GetMapping("/list")
    public TableDataInfo list(JaCase jaCase) {
        startPage();
        List<JaCase> list = jaCaseService.selectJaCaseList(jaCase);
        return getDataTable(list);
    }

    /**
     * 导出案件列表
     */
    // @RequiresPermissions("competition:case:export")
    @Log(title = "案件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JaCase jaCase) {
        List<JaCase> list = jaCaseService.selectJaCaseList(jaCase);
        ExcelUtil<JaCase> util = new ExcelUtil<JaCase>(JaCase.class);
        util.exportExcel(response, list, "案件数据");
    }

    /**
     * 获取案件详细信息
     */
    // @RequiresPermissions("competition:case:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(jaCaseService.selectJaCaseById(id));
    }

    /**
     * 新增案件
     */
    // @RequiresPermissions("competition:case:add")
    @Log(title = "案件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JaCase jaCase) {
        return toAjax(jaCaseService.insertJaCase(jaCase));
    }

    /**
     * 修改案件
     */
    // @RequiresPermissions("competition:case:edit")
    @Log(title = "案件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JaCase jaCase) {
        return toAjax(jaCaseService.updateJaCase(jaCase));
    }

    /**
     * 删除案件
     */
    // @RequiresPermissions("competition:case:remove")
    @Log(title = "案件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(jaCaseService.deleteJaCaseByIds(ids));
    }

    // @RequiresPermissions("competition:case:updateReadCount")
    @Log(title = "案件", businessType = BusinessType.UPDATE)
    @PutMapping("/updateReadCount")
    public AjaxResult updateReadCount(@RequestBody JaCase jaCase) {
        return toAjax(jaCaseService.updateJaCaseReadCount(jaCase));
    }
}
